//
//  BSTabBarController.m
//  Baisijie
//
//  Created by 王建伟 on 2017/3/1.
//  Copyright © 2017年 RangGuangyu. All rights reserved.
//

#import "BSTabBarController.h"
#import "BSNavigationController.h"
#import "BSEssenceViewController.h"
#import "BSNewViewController.h"
#import "BSPublishViewController.h"
#import "BSFriendTrendViewController.h"
#import "BSMeViewController.h"
#import "UIImage+Extension.h"
#import "BSTabBar.h"


@interface BSTabBarController ()

@end

@implementation BSTabBarController

//load方法只会调用一次
//initialize可能会调用多次
+ (void)load {
    UITabBarItem *tabBarItem = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];
    NSMutableDictionary *normalAtt = [NSMutableDictionary dictionary];
    //设置tabBar的字体大小只有在普通状态下有效果
    normalAtt[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    normalAtt[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    [tabBarItem setTitleTextAttributes:normalAtt forState:UIControlStateNormal];
    
    NSMutableDictionary *selectedAtt = [NSMutableDictionary dictionary];
    selectedAtt[NSForegroundColorAttributeName] = BSRGBColor(255, 46, 92, 1);
    [tabBarItem setTitleTextAttributes:selectedAtt forState:UIControlStateSelected];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupAllChildVc];
    [self setupTabBar];
}
- (void)setupAllChildVc {
    //1、精华
    [self setupOneChildVc:[BSEssenceViewController new] normalImage:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon" title:@"精华"];
    //2、最新
    [self setupOneChildVc:[BSNewViewController new] normalImage:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon" title:@"最新"];
    //3、发布
    //4、关注
    [self setupOneChildVc:[BSFriendTrendViewController new] normalImage:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon" title:@"关注"];
    //5、我
    [self setupOneChildVc:[BSMeViewController new] normalImage:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon" title:@"我"];
}
- (void)setupOneChildVc:(UIViewController *)vc normalImage:(NSString *)normalImage selectedImage:(NSString *)selectedImage title:(NSString *)title {
    BSNavigationController *nav = [[BSNavigationController alloc] initWithRootViewController:vc];
    vc.tabBarItem.image = [UIImage imageNamed:normalImage];
    vc.tabBarItem.selectedImage = [UIImage bs_imageOriginalWithNamed:selectedImage];
    vc.tabBarItem.title = title;
    [self addChildViewController:nav];
}
- (void)setupTabBar {
    BSTabBar *tabBar = [[BSTabBar alloc] init];
    [self setValue:tabBar forKey:@"tabBar"];
    [tabBar setPublishBtnClickBlock:^{
//        BSPublishViewController *vc = [BSPublishViewController new];
//        BSNavigationController *nav = [[BSNavigationController alloc] initWithRootViewController:vc];
//        [self presentViewController:nav animated:YES completion:nil];
        BSLog(@"你是谁");
    }];
}

@end
